package com.example.mapp.buildSql;

import com.example.ext.entity.ExtElevatorAppraisal;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by simon on 2017/11/14.
 */
public class AppraisalMappSql {

    public String queryList(ExtElevatorAppraisal extElevatorAppraisal){
        String select = " a.*,b.elevator_num as elevatorNum";
        String table =" elevator_appraisal a  left join elevator b on b.id=a.elevator_id ";
        String whereParam="";
        if(extElevatorAppraisal.getIsFeedBack()!=null && !extElevatorAppraisal.getIsFeedBack().equals("")){
            whereParam+=" and a.is_feed_back = #{isFeedBack} ";
        }
        if(extElevatorAppraisal.getEvaluateType()!=null && !extElevatorAppraisal.getEvaluateType().equals("")){
            whereParam+=" and a.evaluate_type = #{evaluateType} ";
        }
        if(extElevatorAppraisal.getElevatorNum()!=null && !extElevatorAppraisal.getElevatorNum().equals("")){
            whereParam+=" and b.elevator_num = #{elevatorNum} ";
        }
        if(extElevatorAppraisal.getUsedPartyId() != null && !"".equals(extElevatorAppraisal.getUsedPartyId())){
            whereParam+=" and b.used_party_id=#{usedPartyId} ";
        }
        if(extElevatorAppraisal.getMaintenancePartyId() != null && !"".equals(extElevatorAppraisal.getMaintenancePartyId())){
            whereParam+= " and b.maintenance_party_id=#{maintenancePartyId} ";
        }
        String where = " 1=1 "+whereParam;
        return new SQL(){{
            SELECT(select);
            FROM(table);
            WHERE(where);
            ORDER_BY(" ID DESC");
        }
        }.toString();
    }
}
